
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>
  
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/system">系统管理</a></li>
          <li class="active">员工管理</li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>员工管理&nbsp;-&nbsp;员工列表</span></h2>
            </div>
          </div>
          
          <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;">
            <ul class="nav nav-pills x-breadcrumb-nav">
              <c:if test="${empty currentPrincipal.site and !currentPrincipal.areaManager and !currentPrincipal.areaServer}">
                <li class="pull-left"><a href="${ctx.host}/principals?principalType=normal">普通员工</a></li>
              </c:if>
              <li class="pull-left active"><a href="${ctx.host}/principals?principalType=site">门店员工</a></li>
            </ul>
          </div>
          
          <div class="x-toolbar-wrapper clearfix" style="margin-top:20px;">
            <div class="btn-group pull-right">
             <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
               <a href="${ctx.host}/principals/create-area-manager" data-target="#create-area-manager" data-toggle="modal" title="添加大店长" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加大店长
               </a>
             </c:if>
             <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
               <a href="${ctx.host}/principals/create-area-server" data-target="#create-area-server" data-toggle="modal" title="添加运营主管" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加运营主管
               </a>
             </c:if>
             <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
               <a href="${ctx.host}/principals/create-site-manager" data-target="#create-site-manager" data-toggle="modal" title="添加店长" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加店长
               </a>
             </c:if>
             <c:if test="${not empty currentPrincipal.site or not empty persist.getSites(currentPrincipal.id)}">
               <c:if test="${!currentPrincipal.areaServer}">
                 <a href="${ctx.host}/principals/create-coach" data-target="#create-coach" data-toggle="modal" title="添加教练" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                   <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加教练
                 </a>
               </c:if>
               
               <a href="${ctx.host}/principals/create-site-service" data-target="#create-site-service" data-toggle="modal" title="添加门店客服" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                 <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;添加门店客服
               </a>
               <a href="${ctx.host}/principals/search${not empty queryString ? '?' : ''}${queryString}" data-target="#" data-toggle="modal" title="过滤查询" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                 <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
               </a>
             </c:if>
            </div>
          </div>
          
          <table class="table table-striped table-hover x-table" style="margin-bottom:20px;">
            <thead>
              <tr>
                <th>账号名</th>
                <th>手机号码</th>
                <th>角色</th>
                <th>特色标签</th>
                <th>状态</th>
                <th class="text-center">操作</th>
              </tr>
            </thead>
            <tbody>
              <c:forEach var="principal" items="${principals}">
                <tr>
                  <td>${principal.name}</td>
                  <td>${principal.mobile}</td>
                  <td>${secure.roles[principal.authority].description}</td>
                  <td>
                    <c:if test="${not empty  principal.profile}">
                      <c:if test="${not empty  principal.profile.tags}">
                        <c:forEach var="tag" items="${principal.profile.tags}">
		                  <label for="" class="label label-success">${tag.desc}</label>&nbsp;
		                </c:forEach>
                      </c:if>
                    </c:if>
                  </td>
                  <td><span style="color:${principal.disabled ? 'red' : ''}">${principal.disabled ? '锁定' : '未锁定'}</span></td>
                  <td class="text-center">
                    <a href="${ctx.host}/principals/${principal.id}">详情</a>&nbsp;&nbsp;
                    <c:if test="${principal.areaManager or principal.areaServer}">
                      <a href="${ctx.host}/principals/${principal.id}/change-managed-sites" data-toggle="modal" data-target="#change-managed-sites">指定门店</a>&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${principal.coach && !currentPrincipal.areaServer}">
                      <a href="${ctx.host}/principals/${principal.id}/relations" data-toggle="modal" data-target="#bind-relation">指定店长</a>&nbsp;&nbsp;
                    </c:if>
                    <a href="${ctx.host}/principals/${principal.id}/change-status" data-toggle="modal" data-target="#change-status">${principal.disabled ? "重启" : "锁定"}</a>&nbsp;&nbsp;
                    <a href="${ctx.host}/principals/${principal.id}/reset-password" data-target="#reset-password" data-toggle="modal">重置密码</a>
                   </td>
                </tr>
              </c:forEach>
            </tbody>
          </table>
          
          <jsp:include page="/WEB-INF/include/page.jsp">
            <jsp:param name="url" value="principals" />
            <jsp:param name="queryString" value="${queryString}" />
          </jsp:include>
          
        </div>
      </div>
    </div>
  </div>

  <%@ include file="/WEB-INF/include/footer.jsp"%>
  <%@ include file="/WEB-INF/include/script.jsp"%>
  
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/system/principal/principal-list.js">
    <script type="text/javascript">
      require(['page/system/principal/principal-list'] , function(page) {
        page.init();
      })
    </script>
  </d:resource>

</body>

</html>